class Watcher {
  constructor(vm, key, cb) {
    this.vm = vm
    this.key = key
    this.cb = cb
    // 在Dep的静态属性上记录当前watcher对象,当访问数据时把watcher添加到dep的subs中
    Dep.target = this
    // 触发一次getter, 让dep为当前key记录Watcher
    this.oldValue = vm[key]
    // 清空target
    Dep.target = null
  }
  update () { // 负责更新视图
    console.log(this.name, ':我去更新DOM元素了')
    const newValue = this.vm[this.key]
    if (this.oldValue === newValue) return
    this.cb(newValue)
  }
}